package com.study.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

// 实现Runnable接口
class Mythread1 implements Runnable {
    @Override
    public void run() {

    }
}

// 实现Callable接口
class Mythread2 implements Callable {
    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName()+"come in callable");
        return 200;
    }
}

/**
 * @author wanghao
 * @version v1.0
 * @description:
 * @date 2021/12/27 16:26
 * @change [修改时间] [修改者]@[版本号] [修改内容说明]
 */
public class Demo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // Runnable接口创建线程
        new Thread(new Mythread1(),"AA").start();

        FutureTask<Integer> futureTask = new FutureTask<>(new Mythread2());

        FutureTask<Integer> futureTask2 = new FutureTask<>(()->{
            System.out.println(Thread.currentThread().getName()+"come in callable");
            return 1000;
        });

        // 创建一个线程
        new Thread(futureTask2,"join").start();
//        new Thread(futureTask,"tom").start();

        while (!futureTask2.isDone()) {
            System.out.println("wait...");
        }

        System.out.println(futureTask2.get());
//        System.out.println(futureTask.get());

        System.out.println(Thread.currentThread().getName()+"come over");
    }
}
